package android.slc.module.sys.ui.dict.data

import android.slc.base.ui.AppViewModel
import android.slc.fast.utils.FastIntentUtils
import android.slc.box.core.scope.IntentScope

/**
 * @author slc
 * @date 2022/03/21 下午 3:34
 */
open class DictDataPageVm : AppViewModel() {
    lateinit var dictType: String
        private set
    val addEditIntentScope = IntentScope()
    val dictDataPageVmBox by lazy {
        initDictDataPageVmBox()
    }

    open fun initVm() {
        this.dictType = FastIntentUtils.getDataByBundle(intentScope.bundle)
        registerVmBox(dictDataPageVmBox)
        dictDataPageVmBox.dictType = this.dictType
        dictDataPageVmBox.firstRefresh()
        addEditIntentScope.subscribeRefreshList(loadIntentScopeNotification)
    }

    protected open fun initDictDataPageVmBox(): DictDataPageVmSub {
        return DictDataPageVmSub()
    }

    override fun onIntentRefreshList(payload: Any?) {
        super.onIntentRefreshList(payload)
        this.dictDataPageVmBox.firstRefresh()
    }

    override fun onCleared() {
        super.onCleared()
        addEditIntentScope.unSubscribeRefreshList(loadIntentScopeNotification)
    }
}